﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EasyPiano
{
    public partial class AddKeyForm : Form
    {
        public KeyMusic result;

        public AddKeyForm()
        {
            InitializeComponent();
        }

        private void cb_key_KeyUp(object sender, KeyEventArgs e)
        {
            Keys key = e.KeyCode;
            cb_key.SelectedItem = key.ToString();
        }

        private void AddKeyForm_Load(object sender, EventArgs e)
        {
            foreach (var key in Enum.GetNames(typeof(Keys)))
            {
                cb_key.Items.Add(Enum.Parse(typeof(Keys), key).ToString());
            }
            if(result!=null)
            {
                cb_key.SelectedItem = result.key.ToString();
                ssc_sound.musicSoreText = Util.SoundIndexToString(result.index);
                //for (int i = 0; i < GlobalData.soundsPath.Length; i++)
                //{
                //    if(GlobalData.soundsPath[i] == result.fileName.ToString())
                //    {
                //        ssc_sound.musicSoreText = Util.SoundIndexToString(i);
                //        break;
                //    }
                //} 
            }
        }

        private void bt_ok_Click(object sender, EventArgs e)
        {
            if (cb_key.SelectedIndex != -1 && ssc_sound.SelectedIndex != -1)
            {
                Keys key = (Keys)Enum.Parse(typeof(Keys), cb_key.SelectedItem.ToString());
                int sound = ssc_sound.SelectedIndex;
                result = new KeyMusic(key, sound);
                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
